home *** CD-ROM | disk | FTP | other *** search
- /*
- CDSetTrackTitle - An XFCN to set the title of the Track.
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C CDSetTrackTitle.c
- link -sn Main=CDSetTrackTitle -sn STDIO=CDSetTrackTitle ∂
- -sn INTENV=CDSetTrackTitle -rt XFCN=42 ∂
- -m CDSetTrackTitle CDSetTrackTitle.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
- #include <ToolUtils.h>
-
- /* prototype definitions for functions */
- OSErr ReadQ(short, short *, short *, short *, short *);
- OSErr GetTrackTitle(unsigned long, short, StringPtr, long *);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDSetTrackTitle
- *
- * Purpose: set the title of this Track.
- *
- * Returns: 0 if no error
- * whatever driver/io errors we might have encountered
- * otherwise.
- *
- * Side Effects:
- *
- * Description: We need 1 parameter: the new name for the Track.
- * We'll accept a second optional parameter: the track
- * number of the track we want to set.
- *
- * Get the ioRefNum that we got from previously calling
- * CDOpen() by accessing the famous global.
- *
- * Look in the System Folder for the file
- * "CD Remote Programs". Open that file, look at the
- * IndX resource to find out if we've got a matching
- * index. If we do, look up the STR# resource
- * referenced and modify that STR#'s first string to
- * be the new string. If we don't, create a new disc
- * entry and then modify the new STR#'s first string
- * to be the input string.
- *
- * Simple, really.
- *
- ************************************************************************/
- pascal void
- CDSetTrackTitle(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- OSErr result;
- short ioRefNum;
- short vRefNum;
- short resFile;
- Handle refHandle;
- Handle strHandle;
- short strListID;
- unsigned long discID;
- short numberOfTracks;
- Str255 title;
- Str255 newTitle;
- Str31 returnString;
- short trackToFind;
- short minute, second, block;
- Str31 fileName;
- long titleOffset;
-
- strcpy(title, "\p");
- titleOffset = 2L; /* point past word count in STR# */
-
- /* Must be 1 or 2 parameters */
- if ((paramPtr->paramCount) != 1)
- {
- if ((paramPtr->paramCount) != 2)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
- }
- /* check that size of input parameter is less than 255 chars */
- if (strlen(*(paramPtr->params[0])) > 255)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum, vRefNum pair and split them out. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- vRefNum = ioRefNum >> 16;
- ioRefNum &= 0xFFFF;
-
- result = noErr;
-
- /* 1st (possibly only) parameter is a Track title string */
- HandleToPString(paramPtr->params[0], (Ptr)newTitle);
-
- /* if we have a 2nd parameter, it's the track to set */
- if (paramPtr->paramCount == 2)
- trackToFind = atoi(*(paramPtr->params[1]));
- else
- result = ReadQ(ioRefNum, &trackToFind, &minute, &second, &block);
-
- GetIndString(fileName, STR_ID, DRIVENAME);
- if (fileName == (Str31)0)
- result = ResError();
-
- if (result == noErr)
- {
- resFile = OpenSystemResFile(fileName);
- if (resFile == -1)
- result = ResError();
- }
-
- if (result == noErr)
- result = IDDisc(ioRefNum, &discID);
-
- if (result == noErr)
- result = GetNumberTracks(ioRefNum, &numberOfTracks);
-
- if (result == noErr)
- if (FindIndex(discID, &strListID) == false)
- result = AddDisc(discID, numberOfTracks);
-
- if (result == noErr)
- if (FindIndex(discID, &strListID) == false)
- result = fnfErr;
- /* something's badly wrong at this point */
- /* we've failed to create a valid program entry */
- /* and we're hosed */
-
- if (result == noErr)
- result = GetTrackTitle(strListID, trackToFind, title, &titleOffset);
-
- if (result == noErr)
- {
- strHandle = Get1Resource('STR#', strListID);
- if (strHandle == nil)
- result = ResError();
- }
-
- if (result == noErr)
- Munger(strHandle, titleOffset, title, title[0]+1, newTitle, newTitle[0]+1);
-
- if (result == noErr)
- {
- ChangedResource(strHandle);
- result = ResError();
- }
- if (result == noErr)
- {
- WriteResource(strHandle);
- result = ResError();
- }
-
- CloseResFile(resFile);
-
- /* Convert result to string & return it */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
-
-
-
- /************************************************************************
- *
- * Function: ReadQ
- *
- * Purpose: return current Q subcode address data
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: none
- *
- * Description: Simply call the driver. Return track number and
- * absolute minute, second, block.
- *
- ************************************************************************/
- OSErr
- ReadQ(refNum, trackNo, minute, second, block)
- short refNum;
- short *trackNo;
- short *minute;
- short *second;
- short *block;
- {
- CDParam myPB;
- OSErr result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = READQ;
-
- result = PBControl(&myPB, false);
-
- if (result == noErr)
- {
- *trackNo = (short) BCD2DECIMAL(myPB.csParam[1]);
- *minute = (short) BCD2DECIMAL(myPB.csParam[6]);
- *second = (short) BCD2DECIMAL(myPB.csParam[7]);
- *block = (short) BCD2DECIMAL(myPB.csParam[8]);
- }
- return result;
- }
-
-
-
- /************************************************************************
- *
- * Function: GetTrackTitle
- *
- * Purpose: get the track title
- *
- * Returns: OSErr
- * normally noErr. If I can't get a resource, I'll
- * return whatever ResError tells me.
- *
- * Side Effects: fills in title and offset
- *
- * Description: loop through the CD Remote Programs PROG and STR#
- * resources, trying to match the track number.
- *
- ************************************************************************/
- OSErr
- GetTrackTitle(rsrcID, trackNo, title, offset)
- unsigned long rsrcID;
- short trackNo;
- StringPtr title;
- long *offset;
- {
- Handle progHandle;
- short *prog;
- short limit;
- short realTrackNo;
- OSErr result;
-
- result = noErr;
-
- progHandle = Get1Resource('ProG', rsrcID);
- if (progHandle == nil)
- result = ResError();
- if (result == noErr)
- {
- prog = (short *) *progHandle;
- limit = prog[0];
- GetIndString(title, rsrcID, 1);
- for (realTrackNo = 1; realTrackNo <= limit; realTrackNo++)
- {
- *offset += title[0];
- GetIndString(title, rsrcID, realTrackNo+1);
- if (BCD2DECIMAL(prog[realTrackNo] & 0x00FF) == trackNo)
- break;
- }
- }
- return result;
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-